//
//  IMIBaseEvent.m
//  IMIFramework
//
//  Created by Travis on 09-7-28.
//  Copyright 2009 imi.im All rights reserved.
//

#import "IMIBase/IMIBaseEvent.h"


@implementation NSEvent

+(NSEvent*)eventWithKey:(NSString*)key withObject:(id)data{
	NSEvent *event=[NSNotification notificationWithName:key object:[[data retain] autorelease]];
	return event;
}

- (id) init
{
	self = [super init];
	if (self != nil) {
		
	}
	return self;
}


@end

@implementation NSObject(EventDispatcher)

-(void)dispatchEvent:(NSEvent*)event{
	NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
	[nc postNotification:event];
}
-(void)addEventListener:(id)target forKey:(NSString*)key withFunction:(SEL)func{
	NSAssert([target respondsToSelector:func],@"Target does not respondsToSelector");
	NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
	[nc addObserver:target selector:func name:key object:nil];
}
-(void)removeEventListener:(id)target forKey:(NSString*)key{
	NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
	[nc removeObserver:target name:key object:nil];
}

@end